import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

import '../../../style/style.dart';

class FCommonSelectBottomSheet extends StatelessWidget {
  const FCommonSelectBottomSheet({Key? key, required this.values, required this.current}) : super(key: key);
  final List<String> values;
  final int current;

  static Future<int?> show(List<String> values, int current) async {
    var r = await Get.bottomSheet(FCommonSelectBottomSheet(values: values, current: current), isScrollControlled: true, backgroundColor: Colors.transparent, elevation: 0);
    return r is int ? r : null;
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      margin: const EdgeInsets.all(16),
      padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 16),
      decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.circular(10)),
      child: ListView.separated(
          shrinkWrap: true,
          physics: const NeverScrollableScrollPhysics(),
          itemBuilder: (context, index) {
            bool selected = index == current;
            TextStyle style = selected ? TextStyle(fontSize: 16, height: 1, fontWeight: FontWeight.w600, color: kAppThemeColor) : const TextStyle(fontSize: 16, height: 1, color: Colors.black54);
            return CupertinoButton(
              padding: const EdgeInsets.symmetric(horizontal: 16),
              minSize: 50,
              borderRadius: BorderRadius.circular(10),
              color: selected ? kAppThemeColor.withOpacity(0.1) : null,
              child: FittedBox(child: Text(values[index], maxLines: 1, style: style)),
              onPressed: () => Get.back(result: index),
            );
          },
          separatorBuilder: (context, index) => const SizedBox(height: 10),
          itemCount: values.length),
    );
  }
}
